﻿<include file="Public:_head" />
<include file="Public:left" />
	<script type="text/javascript" charset="utf-8" src="com_statics/ueditor/wx_ueditor.config.js"></script>
	<script type="text/javascript" charset="utf-8" src="com_statics/ueditor/ueditor.all.min.js"> </script>
	<script type="text/javascript" src="com_statics/js/ajaxfileupload.js"></script>
	<div id="neirong">
 		<!--<h2 class="lm_title">多图文消息</h2>-->
			<div id="AddDoc">
				<h3 class="subTitle"><img src="com_statics/images/icon_5.gif" alt="图片描述" style="left:9px;"/>多图文消息<span>添加多图文消息，方便关键字调用！</span></h3>
				<div class="leftside">
					<div id="DocPreview" class="Preview_Element">
						<h3 id="demo_title_top">{$reply.content.title}</h3>
						<div class="pic">
							<img id="demo_img_url_top" src="{$reply.content.pic.url}" alt="图片描述" />
						</div>
						<div class="operation height226">
							<a href="javascript:void(0)" rate="top" class="btn_edit">编辑</a>
						</div>
					</div>
					<div id="DocPreview_more" rate="{$reply.length}">
						<ul>
							<volist name="reply.content_more" id="cm">
							<li id="demo_{$i}" class="Preview_Element">
								<div class="pre_title" id="demo_title_{$i}">{$cm.title}</div>
								<div class="pre_pic pic_more">
									<img id="demo_img_url_{$i}" src="{$cm.pic.url}" width="78" height="78" />
								</div>
								<div class="operation height103">
									<a href="javascript:void(0)" rate="{$i}" class="btn_edit">编辑</a>
								</div>
							</li>
							</volist>
						</ul>
					</div>
					<div class="btnbox">
						<a href="javascript:void(0)" class="btn_addpic">&nbsp;</a>
					</div>
				</div>
                <!-- DocPreview结束 -->
				<form name="form" method="post" action="{:U('Weixin/save_reply_image_more',array('reply_id'=>$reply['reply_id']))}" onSubmit="return checkmore();">
                <div id="AddDocForm">
					<div id="formElement_top" class="adddocform">
						<dl>
							<dt>关键字（多个关键字用空格隔开）<font color="red">*</font>：</dt>
							<dd><div class="border"><input name="key" type="text" class="text" value="{$reply.key}" /></div> <span class="xuanxian"><input name="fuzzy" type="checkbox" value="1" <if condition="$reply.fuzzy eq 1">checked</if> /> 模糊匹配 </span>
							<span class="clear"></span>
							</dd>
							<dt>标题 <font color="red">*</font>：</dt>
							<dd><div class="border"><input name="content[top][title]" type="text" class="text title" id="title_top" rate="top" value="{$reply.content.title}" /></div>
							<span class="clear"></span>
							</dd>
							<dt>作者：</dt>
							<dd><div class="border"><input name="content[top][author]" type="text" class="text" value="{$reply.content.author}" /></div>
							<span class="clear"></span>
								<div class="uploadbox">
								   <p> 封面<span>（大图片建议尺寸：900像素*500像素）<font color="red">*</font></span></p>
									<div class="img_preview_top">
										<img src="{$reply.content.pic.url}" id="img_url_top" width="300" height="167" /><a href="javascript:void(0)" rate="top" class="imgdel">删除</a>
										<input name="content[top][picaid]" id="picaid_top" type="hidden" value="{$reply.content.picaid}" />
									</div>
									<div class="img_upload_top" style="display:none">
										<input type="file" id="fileToUpload_top" class="fileToUpload" rate="top" name="fileToUpload" style="display:none">
										<a href="javascript:void(0)" id="clickupload" rate="top" class="btn_upload">上传</a>
									</div>
								</div>
							</dd>
							<dt>正文 <font color="red">*</font>：</dt>
							<dd>
								<script id="content_top" name="content[top][content]" type="text/plain" style="width:400px;height:300px">{$reply.content.content}</script>
							</dd>	
							<dt>链接：</dt>
							<dd><div class="border"><input name="content[top][url]" type="text" class="text" style="width:389px;" value="{$reply.content.url}" /></div> <span class="clear"></span></dd>
						</dl>
						<span class="jiantou"></span>
					</div>
					<volist name="reply.content_more" id="cm">
					<div id="formElement_{$i}" class="adddocform" style="margin-top:{$cm.offset}px;display:none">
						<dl>
							<dt>标题 <font color="red">*</font>：</dt>
							<dd><div class="border"><input name="content[mini][{$i}][title]" type="text" class="text title" id="title_{$i}" rate="{$i}" value="{$cm.title}" /></div>
							<span class="clear"></span>
							</dd>
							<dt>作者：</dt>
							<dd><div class="border"><input name="content[mini][{$i}][author]" type="text" class="text" value="{$cm.author}" /></div>
							<span class="clear"></span>
								<div class="uploadbox">
								   <p> 封面<span>（大图片建议尺寸：900像素*500像素）<font color="red">*</font></span></p>
									<div class="img_preview_{$i}">
										<img src="{$cm.pic.url}" id="img_url_{$i}" width="300" height="167" /><a href="javascript:void(0)" rate="{$i}" class="imgdel">删除</a>
										<input name="content[mini][{$i}][picaid]" id="picaid_{$i}" type="hidden" value="{$cm.picaid}" />
									</div>
									<div class="img_upload_{$i}" style="display:none">
										<input type="file" id="fileToUpload_{$i}" class="fileToUpload" rate="{$i}" name="fileToUpload" style="display:none">
										<a href="javascript:void(0)" id="clickupload" rate="{$i}" class="btn_upload">上传</a>
									</div>
								</div>
							</dd>
							<dt>正文 <font color="red">*</font>：</dt>
							<dd>
								<script id="content_{$i}" name="content[mini][{$i}][content]" type="text/plain" style="width:400px;height:300px;">{$cm.content}</script>
							</dd>	
							<dt>链接：</dt>
							<dd><div class="border"><input name="content[mini][{$i}][url]" type="text" class="text" style="width:389px;" value="{$cm.url}" /></div> <span class="clear"></span></dd>
						</dl>
						<span class="jiantou"></span>
						<script>
									var edit_{$i} = UE.getEditor('content_{$i}');
						</script>
					</div>
					</volist>
                </div>
                <!-- AddDocForm结束 -->
                <span class="clear"></span>
                <!-- 清除浮动 -->
				<div class="form_submit"><button class="btn_send"  type="submit">提交</button></div>
				</form>
            </div>
            <!-- AddDoc结束 -->
	</div>
	<!-- neirong结束 -->
	<span class="clear"></span>
	<!-- 清除浮动 -->
</div>
<!-- container结束 -->
<script>
function checkmore(){
	var num = "{$i}";
	var nu = "{$num}";
	if($('#formElement_'+num).is(':hidden')){
	}else{
			var b = $("input[name='content[mini]["+num+"][title]']").attr('value');
			var c = $("input[name='content[mini]["+num+"][picaid]']").attr('value');
			var d = $("textarea[name='content[mini]["+num+"][content]']").attr('value');
		}
	if($('#formElement_'+nu).is(':hidden')){
	}else{
			var b = $("input[name='content[mini]["+nu+"][title]']").attr('value');
			var c = $("input[name='content[mini]["+nu+"][picaid]']").attr('value');
			var d = $("textarea[name='content[mini]["+nu+"][content]']").attr('value');
	}	
	if($('#formElement_top').is(':hidden')){}else{
		var a = $("input[name='key']").attr('value');
			var b = $("input[name='content[top][title]']").attr('value');
			var c = $("input[name='content[top][picaid]']").attr('value');
			var d = $("textarea[name='content[top][content]']").attr('value');
		   if(a ==""){
		        alert('关键字不能为空！');
		        return false;
		    }
	}
	
    if(b ==""){
        alert('标题不能为空！');
        return false;
    }
    if(c ==""){
        alert('封面不能为空！');
        return false;
    }
    if(d ==""){
        alert('正文不能为空！');
        return false;
    }
}
	$(document).ready(function(){
		var ue = UE.getEditor('content_top');
		$("#clickupload").live('click',function(){
			num = $(this).attr('rate');
			$("#fileToUpload_"+num).click();
		});
		$(".fileToUpload").live('change',function(){
			num = $(this).attr('rate');
			$.ajaxFileUpload(
				{
					url:"__URL__/uploadpic",
					secureuri:false,
					fileElementId:'fileToUpload_'+num,
					dataType: 'json',
					data:{type:'weixin'},
					success: function (res){
						$(".img_upload_"+num).hide();
						$("#img_url_"+num).attr('src',res.info.url);
						$("#demo_img_url_"+num).attr('src',res.info.url);
						$("#picaid_"+num).val(res.aid);
						$(".img_preview_"+num).show();
					},
					error: function (res){
						alert(res);
					}
				}
			)
		});
		$(".title").live('keyup',function(){
			num = $(this).attr('rate');
			$("#demo_title_"+num).html($("#title_"+num).val());
		});
		$(".btn_addpic").click(function(){
			del_html = '';
			length = $("#DocPreview_more").attr("rate");
			length++;
			if(length<=9){
				if(length!=1){
					del_html = '<a href="javascript:void(0)" rate="'+length+'" class="btn_del">删除</a>';
				}
				demo_html = '<li id="demo_'+length+'" class="Preview_Element"><div class="pre_title" id="demo_title_'+length+'">这是标题</div><div class="pre_pic pic_more"><img id="demo_img_url_'+length+'" src="" width="78" height="78" /></div><div class="operation height103"><a href="javascript:void(0)" rate="'+length+'" class="btn_edit">编辑</a>'+del_html+'</div></li>';
				element = $("#DocPreview_more ul");
				element.append(demo_html);
				offsettop = $("#demo_"+length).offset().top-215;
				$("#DocPreview_more").attr('rate',length);
				$.post('__URL__/addelement',{num:length,top:offsettop},function(res){
					$("#AddDocForm .adddocform").each(function(){
						$(this).css('display','none');
					});
					$("#AddDocForm").append(res);
					edit = 'edit_'+length;
					var edit = UE.getEditor('content_'+length);
				});
			}else{
				alert('最多只能添加10条图文');
				return false;
			}
		});
		$(".Preview_Element").live('mouseover',function(){
			$(this).find(".operation").show();
		});
		$(".Preview_Element").live('mouseleave',function(){
			$(this).find(".operation").hide();
		});
		$(".operation .btn_edit").live('click',function(){
			$("#AddDocForm .adddocform").each(function(){
				$(this).css('display','none');
			});
			length = $(this).attr('rate');
			$("#formElement_"+length).show();
		});
		$(".operation .btn_del").live('click',function(){
			$("#AddDocForm .adddocform").each(function(){
				$(this).css('display','none');
			});
			length = $(this).attr('rate');
			$("#formElement_"+length).remove();
			$("#demo_"+length).remove();
			length = $("#DocPreview_more").attr("rate");
			length--;
			$("#DocPreview_more").attr('rate',length);
			$("#formElement_"+length).show();
		});
		$(".imgdel").click(function(){
			num = $(this).attr('rate');
			$(".img_preview_"+num).hide();
			$(".img_upload_"+num).show();
			$("#demo_img_url_"+num).attr('src','');
		});
	});
</script>
<include file="Public:bottom" />
